#include "riscv_asm.h"
#include "common.S"

.text

# void switch_to(struct context *next);
# a0: pointer to the context of the next task
.globl switch_to
switch_to:

	csrw	mscratch, a0				# switch mscratch to point to the context of the next task

	REG_L	t0, 31*SIZE_REG(a0)			# set mepc from the pc of the next task
	csrw	mepc, t0

	mv	t6,	a0							# move a0 to t6, because a0 is used by RESTORE_REG
	RESTORE_REG	t6						# restore all general registers

	# do actual contest switching,
	# Notice this will enable global interrupt
	mret

.end





